const path = require('path')
const getJson = require('../utils/file_utils')
module.exports = async (ctx, next) => {
  const url = ctx.url // api/seller
  let filePath = url.replace('/api', '') //seller
  // 拼接资源的路径
  filePath = '../data' + filePath + '.json' //../data/seller.json
  // 使用绝对路径
  filePath = path.join(__dirname, filePath)

  try {
    const ret = await getJson(filePath)
    ctx.body = ret
  } catch (error) {
    ctx.body = {
      msg: '文件资源不存在',
      code: 404,
    }
  }
  //   await next()
}
